package com.etoak.rst.sys.dish.controller;

import com.etoak.rst.sys.dish.DTO.CategoryDTO;
import com.etoak.rst.sys.dish.entity.Category;
import com.etoak.rst.sys.dish.service.IDishService;
import com.etoak.rst.sys.util.JsonResponse;
import com.etoak.rst.sys.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/dishtype")
@RestController
public class DishTypeController {
    @Autowired
    private IDishService service;


    /*菜品分类的查询
     * */
    @RequestMapping("/querySomE4Cate")
    public JsonResponse querySome(CategoryDTO dto){
        List<Category> data = service.querySome(dto);
        PageInfo<Category> info = new PageInfo<>(data);
        return data!=null && data.size()>0?
                Result.success("200","success",info):
                Result.failed("200011","failed","查询失败");
    }

    @GetMapping
    public JsonResponse queryAll(){
        List<Category> data = service.queryAll();
        return data!=null && data.size()>0?
                Result.success("200","success",data):
                Result.failed("200011","failed","查询失败");
    }


    /*菜品分类添加
     * */
    @PostMapping("/addCateGory")
    public JsonResponse addCateGory(@RequestBody Category category){
        boolean flag = service.addCateGory(category);
        return flag?Result.success("200","success","添加成功"):
                Result.failed("200012","failed","添加失败");
    }

    /*菜品分类修改
     * */
    @PutMapping("/updateCategory")
    public JsonResponse updateCategory(@RequestBody Category category){
        boolean flag = service.updateCategory(category);
        return flag?Result.success("200","success","修改成功"):
                Result.failed("200012","failed","修改失败");
    }

    /*菜品分类删除
     * */
    @GetMapping("/{id}")
    public JsonResponse delCategory(@PathVariable int id){
        boolean flag = service.delCategory(id);
        return flag?Result.success("200","success","删除成功"):
                Result.failed("200012","failed","删除失败");
    }

    /* 菜品分类状态修改
     * */
    @RequestMapping("/cateStatue")
    public JsonResponse cateStatue(@RequestBody Category category){
        boolean flag = service.cateStatue(category);
        return flag?Result.success("200","success","状态修改成功"):
                Result.failed("200012","failed","状态修改失败");
    }
}
